/*
 * blink.c
 *
 * Created: 10/6/2013 11:22:37 AM
 *  Author: Tim
 */ 


/* RTC Background Explanation

The Xmega series of processors contain what is called a real time clock (RTC). A
real time clock is characterized by having a frequency of 32.768 kHz (32768 Hz).  
Why is this frequency so special, you may wonder.  Well 2^15 = 32768 exactly.  

Generally speaking this rtc clock source is fed into a digital counter 
(clock + counter = timer).  When the counter value equals 32768 a second has 
elapsed.  This is how digital clocks keep track of time.  Its literally that simple. 

*/

//the below statement is called a define
#define numberOfMilliSeconds	100		//change this number to speed up or slow down blinking of the led. 



/*
a define statement is a simple way of equating text to value.  The above define
"defines" numberOfMilliSeconds to equal 100. Notice the format here.  There is 
no equal sign and there is no ; at the end of the statement.  This is because
a define is a preprocessor method like an include.  The statement simply tells
the compiler to insert 100 for every instance of the text numberOfMilliSeconds.

Why would you use a define you may wonder.  Lets say we wrote some code with a 
lot of intentionally identical delays.  After testing you realize you would 
like to increase the delay time.  Its easier to change the amount in a define
than in every delay call in the source code.

Any time there is a need for a global static value, a define is the way to go
*/



#include "../src/Epiphany.h" //this call included all the files in src

void setup()
{
	//this function sets the db led pin direction to output (note this is actually a macro)
	dbledInit();
	
	//This function needs to be called in order to get the RTC clock running 
	RTC_DelayInit();
	
}

void loop()
{
	//This statement evaluates whether the RTC delay has elapsed
	//delay over is just a defined flag thats easily readable 
	if(delayOver)
	{
		dbledTgl();
		RTC_Delay_ms(numberOfMilliSeconds);
	}
}